<style scoped>
  .weui-form-preview {
    background-color: #fff;
    margin: 5px;
    border-radius: 5px;
  }

  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }

  .rj-cell {
    display: inline-block;
    font-size: 0;
    padding: 5px 15px;
  }

  .rj-cell.max span {
    font-size: 16px;
    padding-right: 20px;
  }

  .rj-cell label {
    color: #333;
    font-size: 14px;
  }

  .rj-cell span {
    padding-left: 5px;
    font-size: 14px;
    color: #333;
  }

  .rj-cell.note {
    width: 100%;
  }

  .rj-cell.note label {
    float: left;
  }

  .rj-cell.note span {
    width: 80%;
    display: inline-block;
  }

  .weui-panel {
    background: #eee;
  }

  .rj-cont-tit {
    margin: 0;
    border-radius: 0;
  }

  .weui-panel {
    margin-top: 0;
    text-align: left;
  }

  .attachimg {
    /*width: 100%;*/
  }

  .tit label, .tit span {
    font-size: 16px;
  }

  .tit label {
    padding-right: 20px;
  }

  .weui-panel.weui-panel_access {
    padding-bottom: 10px;
  }

  .weui-panel__bd:not(.base) {
    width: 98%;
    /*padding: 0 1% 2px 1%;*/
  }

  .rj-cont-tit:not(.base) {
    border-radius: 5px;
  }

  .weui-cell {
    background: #fff;
  }

  .weui-cells__title {
    text-align: left;
    background: #eee;
  }

  .oitem {
    padding: 3px;
  }

  #acts span {
    font-size: 14px;
  }

  .weui-label {
    text-align: left;
  }

  .weui-media-box {
    text-align: left;
  }

  .weui-panel {
    background: #eee;
  }

  .rj-cont-tit {
    margin: 0;
    border-radius: 0;
  }

  .weui-panel {
    margin-top: 0;
    text-align: left;
  }

  .hd .weui-grid.js_grid {
    font-weight: 600;
  }

  .weui-grid.js_grid {
    width: 33.3%;
    padding: 10px 1px;
  }
  .weui-grid__label {
    text-overflow: initial;
  }

  /*.view-wrap {*/
  /*  background: #eee;*/
  /*}*/
  .section {
    width: auto;
    margin: 5px;
    border-radius: 5px;
    text-align: left;
    overflow: hidden;
  }
  .itemSection {
    background: #fafafa;
    margin: 3px;
  }
  .itemTit {
    color: #999;
    font-size: 12px;
    margin-left: 15px;
  }
</style>
<template>
  <div class="comon" style="background: #eee;">
    <div
      style="height: 50px; line-height: 50px; background: #fff; text-align: center; font-size: 16px; border-bottom: 1px solid #bdbbbc; position: relative">
      生产领料详情
      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px"/>
      </a>
    </div>
    <!--    主表信息-->
    <div class="weui-form-preview" style="background: #fff;">
      <div class="weui-form-preview__hd">
        <label class="weui-form-preview__label">编号</label>
        <em class="weui-form-preview__value">{{baseInfo.code}}</em>
      </div>
      <div class="weui-form-preview__bd">
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">生产计划编号</label>
          <span class="weui-form-preview__value">{{baseInfo.produceplanCode}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">所在班组</label>
          <span class="weui-form-preview__value">{{baseInfo.deptName}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">领料类别</label>
          <span class="weui-form-preview__value">{{baseInfo.picktypename}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">出库库房</label>
          <span class="weui-form-preview__value">{{baseInfo.strname}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">库存组织</label>
          <span class="weui-form-preview__value">{{baseInfo.orgname}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">状态</label>
          <span class="weui-form-preview__value">{{baseInfo.statusname}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">备注</label>
          <span class="weui-form-preview__value">{{baseInfo.remark}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">提交人</label>
          <span class="weui-form-preview__value">{{baseInfo.createName}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">创建时间</label>
          <span class="weui-form-preview__value">{{baseInfo.createtime}}</span>
        </div>
        <div class="weui-form-preview__item" v-if="baseInfo.files && baseInfo.files.length > 0">
          <label class="weui-form-preview__label">附件</label>
          <a v-for="(item, index) in baseInfo.files" :href="item.url">
            <span class="weui-form-preview__value">{{item.imagename}}</span>
          </a>
        </div>
      </div>
    </div>
    <!--    明细信息-->
    <div class="weui-panel__hd" style="text-align: left;">货品明细</div>
    <div class="weui-panel__bd" style="background: #fff;">
      <div class="weui-grids">
        <div class="row hd">
          <a href="#" class="weui-grid js_grid fir">
            <p class="weui-grid__label">
              产品
            </p>
          </a>
          <a href="#" class="weui-grid js_grid sec">
            <p class="weui-grid__label">
              规格
            </p>
          </a>
          <a href="#" class="weui-grid js_grid fou">
            <p class="weui-grid__label">
              领料数量
            </p>
          </a>
        </div>
        <template v-for="item in baseInfo.items">
          <div class="row">
            <a href="#" class="weui-grid js_grid fir">
              <p class="weui-grid__label">
                {{item.product}}
              </p>
            </a>
            <a href="#" class="weui-grid js_grid sec">
              <p class="weui-grid__label">
                {{item.spename}}
              </p>
            </a>
            <a href="#" class="weui-grid js_grid fou">
              <p class="weui-grid__label">
                {{item.weight}} {{item.stockunit ? item.stockunit : ''}}
              </p>
            </a>
          </div>
        </template>
      </div>


    </div>
    <!--    生产数据统计-->
    <div v-if="outweight > 0">
      <div class="weui-panel__hd" style="text-align: left;">生产数据统计</div>
      <div class="weui-panel__bd section" style="background: #fff;">
        <CommonChart :whinformweight="whinformweight" :failedweight="failedweight" :materweight="materweight" :scrapweight="scrapweight" :outweight="outweight" :lossweight="lossWeight"></CommonChart>
      </div>
    </div>
    <!--    出库信息-->
<!--    <div v-if="outweight > 0">-->
      <div class="weui-panel__hd" style="text-align: left;">出库信息</div>
      <div class="weui-panel__bd section" style="background: #fff;">
        <div v-for="(item, index) in outforms">
          <div class="rj-cell max">
            <label>操作人员：</label>
            <span>{{item.operator}}</span>
            <span>{{item.createtime}}</span>
          </div>
          <p class="itemTit"> 出库明细 </p>
          <div v-for="(product, index) in item.items" style="border-top: 1px solid #ccc;" >
            <div class="itemSection">
              <div class="rj-cell max"  >
                <label> 产品：</label>
                <span>{{product.product}} {{product.spename}}</span>
              </div>
              <div class="rj-cell max"  >
                <label> 数量：</label>
                <span>{{product.weight}} {{product.stockunit}} {{product.house}}</span>
              </div>
              <div class="rj-cell max"  v-if="product.cosobj" >
                <label><span>成本对象：</span></label>
                <span>{{product.cosobj.productName}} {{product.cosobj.name}}</span>
              </div>
            </div>
          </div>
          <div class="weui-media-box weui-media-box_text uploaderFiles" v-if="item.imgs && item.imgs.length > 0">
            <p class="exp" style="font-size: 12px;color: #999;padding: 5px 0;">出库单</p>
            <div class="exp uploaderFiles" style="display: inline-block;">
              <img class="attachimg" style="padding-right: 5px;"  v-for="(image, index) in item.imgs " :key="image.guid"  alt="" onerror="javascript:this.src='../../../../static/image/default.png';this.onerror = null" :src="image.url + '-suolue.png'" :data-img="image.url + '.png'" />
            </div>
          </div>
<!--        </div>-->
      </div>
    </div>
    <!--    质检单-->
<!--    <div v-if="qaform.status ==1 || qaform.status ==2">-->
<!--      <div class="weui-panel__hd" style="text-align: left;">质检单</div>-->
<!--      <div class="weui-panel__bd section" style="background: #fff;">-->
<!--          <div class="rj-cell max">-->
<!--            <label>质检单编号：</label>-->
<!--            <span>{{item.qacode}}</span>-->
<!--          </div>-->
<!--          <div class="rj-cell max">-->
<!--            <label>抽检数量：</label>-->
<!--            <span>{{qaform.chkpknum}} 包</span>-->
<!--            <span> {{qaform.chkwght}} Kg</span>-->
<!--            <label>合格重量：</label>-->
<!--            <span> {{qaform.okweight}} Kg</span>-->
<!--          </div>-->
<!--        <div class="rj-cell max">-->
<!--          <label>不合格重量：</label>-->
<!--          <span> {{qaform.notokweight}} Kg</span>-->
<!--          <label>不合格率：</label>-->
<!--          <span> {{qaform.unqualifiedchkrate}}%</span>-->
<!--        </div>-->
<!--        <div class="rj-cell max">-->
<!--          <label>土杂重量：</label>-->
<!--          <span> {{qaform.soilchkweight}} Kg</span>-->
<!--          <label>土杂率：</label>-->
<!--          <span> {{qaform.soilchkrate}}%</span>-->
<!--        </div>-->

<!--        <br>-->
<!--        <div class="rj-cell max">-->
<!--          <label>合格率：</label>-->
<!--          <span> {{ Number(100 - qaform.deductrate).toFixed(2)}}  %</span>-->
<!--        </div>-->

<!--        <div class="rj-cell max">-->
<!--          <label>质检人：</label>-->
<!--          <span>{{qaform.operatorname}}</span>-->
<!--          <label>质检时间：</label>-->
<!--          <span>{{qaform.createdate}}</span>-->
<!--        </div>-->
<!--          <div class="weui-media-box weui-media-box_text uploaderFiles" v-if="qaFormImg != undefined && qaFormImg.length > 0">-->
<!--            <p class="exp" style="font-size: 12px;color: #999;padding: 5px 0;">质检单照片</p>-->
<!--            <div class="exp uploaderFiles" style="display: inline-block;">-->
<!--              <img class="attachimg" style="padding-right: 5px;"  v-for="(image, index) in qaFormImg " :key="image.guid"  alt="" onerror="javascript:this.src='../../../../static/image/default.png';this.onerror = null" :src="image.url + '-suolue.png'" :data-img="image.url + '.png'" />-->
<!--            </div>-->
<!--          </div>-->
<!--      </div>-->
<!--    </div>-->
    <!--    入库信息-->
<!--    <div v-if="whinformweight > 0">-->
    <template v-if="whinforms && whinforms.length > 0">
      <div class="weui-panel__hd" style="text-align: left;">入库信息</div>
      <div class="weui-panel__bd section" style="background: #fff;">
        <div v-for="(item, index) in whinforms" :key="item.guid">
          <div class="rj-cell max">
            <label>操作人员：</label>
            <span>{{item.operator}}</span>
            <span>{{item.createdate.substr(0, 10)}}</span>
          </div>
          <p class="itemTit"> 入库明细 </p>
          <div v-for="(product, index) in item.items" style="border-top: 1px solid #ccc;" >
            <div class="itemSection">
              <div class="rj-cell max">
                <label><span style="font-size: 14px;padding: 0;">产品：</span></label>
                <span>{{product.product}}</span>
                <span>{{product.spename}}</span>
              </div>
              <div class="rj-cell max">
                <label>数量：</label>
                <span>{{product.weight}} {{product.stockunit}}</span>
                <span>{{product.room}}</span>
              </div>
            </div>
          </div>
          <div class="weui-media-box weui-media-box_text uploaderFiles" v-if="item.images != undefined && item.images.length > 0">
            <p class="exp" style="font-size: 12px;color: #999;padding: 5px 0;">入库单</p>
            <div class="exp uploaderFiles" style="display: inline-block;">
              <img class="attachimg" style="padding-right: 5px;"  v-for="(image, index) in item.images " :key="image.guid"  alt="" onerror="javascript:this.src='../../../../static/image/default.png';this.onerror = null" :src="image.url + '-suolue.png'" :data-img="image.url + '.png'" />
            </div>
          </div>
        </div>
      </div>
    </template>
<!--    </div>-->
    <!--    退料信息-->
<!--    <div v-if="materweight > 0">-->
      <div class="weui-panel__hd" style="text-align: left;">退料信息</div>
      <div class="weui-panel__bd section" style="background: #fff;">
        <div v-for="(item, index) in maters" :key="item.guid">
          <div class="rj-cell max">
            <label>编号：</label>
            <span>{{item.code}}</span>
          </div>
          <div class="rj-cell max">
            <label>状态：</label>
            <span>{{item.statusname}}</span>
          </div>
          <div class="rj-cell max">
            <label>操作人员：</label>
            <span>{{item.operatorName}}</span>
            <span>{{item.createtime}}</span>
          </div>
          <p class="itemTit"> 货品明细 </p>
          <div v-for="(product, index) in item.items" style="border-top: 1px solid #ccc;" >
            <div class="itemSection">
              <div class="rj-cell max">
                <label><span style="font-size: 14px;padding: 0;">产品：</span></label>
                <span>{{product.productName}}</span>
                <span>{{product.specName}}</span>
              </div>
              <div class="rj-cell max">
                <label>数量：</label>
                <span>{{product.weight}} {{product.stockunit}}</span>
                <span>{{product.shname}}</span>
              </div>
            </div>
          </div>
          <div class="weui-media-box weui-media-box_text uploaderFiles" v-if="item.images != undefined && item.images.length > 0">
            <p class="exp" style="font-size: 12px;color: #999;padding: 5px 0;">退料单</p>
            <div class="exp uploaderFiles" style="display: inline-block;">
              <img class="attachimg" style="padding-right: 5px;"  v-for="(image, index) in item.images " :key="image.guid"  alt="" onerror="javascript:this.src='../../../../static/image/default.png';this.onerror = null" :src="image.url + '-suolue.png'" :data-img="image.url + '.png'" />
            </div>
          </div>
        </div>
      </div>
<!--    </div>-->
    <!--    报废信息-->
    <div v-if="scrapweight > 0">
      <div class="weui-panel__hd" style="text-align: left;">报废信息</div>
      <div class="weui-panel__bd section" style="background: #fff;">
        <div class="rj-cell max tit">
          <label>报废</label>
          <!--            <span>{{scrapweight}}  吨</span>-->
        </div>
        <div v-for="(item, index) in scraps" :key="item.guid">
          <p class="itemTit"> 货品明细 </p>
          <div v-for="(product, index) in item.items" style="border-top: 1px solid #ccc;" >
            <div class="itemSection">
              <div class="rj-cell max">
                <label><span style="font-size: 14px;padding: 0;">产品：</span></label>
                <span>{{product.product}}</span>
                <span>{{product.spename}}</span>
              </div>
              <div class="rj-cell max">
                <label>数量：</label>
                <span>{{product.weight}} {{product.stockunit}}</span>
              </div>
            </div>
          </div>
          <div class="rj-cell max">
            <label>操作人员：</label>
            <span>{{item.operator}}</span>
            <span>{{item.createtime}}</span>
          </div>
          <div class="weui-media-box weui-media-box_text uploaderFiles" v-if="item.images != undefined && item.images.length > 0">
            <p class="exp" style="font-size: 12px;color: #999;padding: 5px 0;">报废单</p>
            <div class="exp uploaderFiles" style="display: inline-block;">
              <img class="attachimg" style="padding-right: 5px;"  v-for="(image, index) in item.images " :key="image.guid"  alt="" onerror="javascript:this.src='../../../../static/image/default.png';this.onerror = null" :src="image.url + '-suolue.png'" :data-img="image.url + '.png'" />
            </div>
          </div>
          <div class="weui-form-preview__ft">
            <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:" v-show="picking.status <= 3 && item.operatorid == userid" @click="delScrap(item.guid)">删除</a>
          </div>
        </div>
      </div>
    </div>
    <!--    审批记录-->
    <SalesOperationLogs7 :orderid="id" :srguid="baseInfo.srguid" :departid="baseInfo.departid" :flowid="flowid"></SalesOperationLogs7>
    <!--    </div>-->
    <!--  </div>-->
    <CommentBom v-if="isReady" :flowid="flowid" :nodeid="nodeid" :id="id" :srguid="baseInfo.srguid" :departid="baseInfo.departid" :model="baseInfo"  navgateUrl="/pickmrial2/PickmrialList" ></CommentBom>
  </div>
</template>

<script>
  import SalesOperationLogs7 from '../common/SalesOperationLogs7'
  import CommentBom from '@/components/common/CommentBom'

  export default {
    name: 'ViewPickmrial2',
    data() {
      return {
        flowid: 30,
        openid: localStorage.openid,//'oIuV2v77MaLCAQILhjI6h6oTWpHI',
        userid: localStorage.userId,//'oIuV2v77MaLCAQILhjI6h6oTWpHI',
        id: '',
        baseInfo: {},
        picking: {},
        scraps: [],
        scrapweight: 0,
        whinforms: [],
        whinformweight: 0,
        failedwhs: [],
        failedweight: 0,
        maters: [],
        materweight: 0,
        outforms: [],
        outweight: 0,
        lossWeight: 0,
        qaform:{},
        qaFormImg:[]
      }
    },
    components: {
      SalesOperationLogs7,
      CommentBom
    },
    created() {
      window.addEventListener('setItem', () => {
        this.openid = localStorage.getItem('openid');
        this.userid = localStorage.getItem('userId');
      })
    },
    mounted() {
      this.id = this.$route.query.id;
      this.getbaseInfo(this.id);
    //图片浏览器
      $('.weui-panel').on('click', '.uploaderFiles .attachimg', function () {
        var num = $(this).parent().children().not(".exp").length;
        var imgArr = [];
        for (var i = 0; i < num; i++) {
          imgArr.push($(this).parent().find('.attachimg').eq(i).data('img'));
        }
        var pnum = $(this).parent().find('.exp').length;
        var index = pnum > 0 ? $(this).index() - pnum : $(this).index();
        var pb = $.photoBrowser({
          items: imgArr,
          initIndex: index
        });
        pb.open();
      });

    },
    methods: {
      packUnit: function(unit, currency) {
        return unit != undefined && unit != '' ? currency == 2 ? '美元/' + unit : '元/' + unit : '';
      },
      getbaseInfo: function (id) {
        this.axios({
          method: 'get',
          url: `/prod-api/produce/pickinglist/${id}`,
        }).then(response => {
          if (response.data.code == 200) {
            let data = response.data;
            console.log(data);
            this.baseInfo = data.data || {};
            // this.picking = data.data;
            this.scraps = data.scraps;
            this.scrapweight = this.toFix6(data.scrapweight != undefined ? data.scrapweight : 0);
            this.whinforms = data.whinforms;
            this.whinformweight = this.toFix6(data.whinformweight != undefined ? data.whinformweight : 0);
            this.failedwhs = data.failedwhs;
            this.failedweight = this.toFix6(data.failedweight != undefined ? data.failedweight : 0);
            this.maters = data.maters;
            this.materweight = this.toFix6(data.materweight != undefined ? data.materweight : 0);
            this.outforms = data.outforms;
            this.outweight = this.toFix6(data.outweight != undefined ? data.outweight : 0);
            this.lossWeight = this.toFix6(this.outweight - this.whinformweight - this.failedweight - this.scrapweight - this.materweight);
            this.qaform = data.qaForm  != null ? data.qaForm : 0;
            this.qaFormImg = data.qaFormImg != null ?data.qaFormImg :0;
            // this.baseItems = response.data.items;
          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
            //不不设置提示
          } else {
            this.toastError('系统错误');
          }
          this.isReady = true;
        });
      },
      delScrap: function (guid) {
        let that = this;
        var object = Object;
        $.confirm("确定删除!", function() {
          that.axios({
            method: 'post',
            url: '/produce/Scrapapply!delete.action',
            params: {scrapapplyid: guid}
          }).then((response) => {
            if (response.data.msg == 'success') {
              if (object.keys(that.$refs).length == 1) {
                $('#scrap').remove();
              }
              that.$refs[guid][0].remove();
              that.toastSuccess('删除成功！');
            } else if (response.data.msg == 'canotdel') {
              that.toastText('无权删除！');
            } else if (response.data.msg == 'outlogin') {
              that.toastText('请重新登录！');
            } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
              //不不设置提示
            } else {
              that.toastError("系统错误");
            }
          })
        }, function() {
          //点击取消后的回调函数
        });
      },
    }
  }
</script>
